package com.yu.util;
import java.util.ArrayList;

import com.qcloud.sms.SmsMultiSender;
import com.qcloud.sms.SmsMultiSenderResult;
import com.qcloud.sms.SmsSingleSender;
import com.qcloud.sms.SmsSingleSenderResult;

/**
 * 腾讯云
 * SmsSDKDemo
 *
 * @author ray
 * @data 2017年5月15日 @time 上午11:42:19
 *
 */
public class QQSMSComponent {
	private static int appid = 1400039364;
	private static String appkey = "8256069db1b028d30e72c69de3817922";
	
	public static int sendSMSInvitation(String mobile,String number) throws Exception {
		
		
		int tmplId = 43477;
		SmsSingleSender singleSender = new SmsSingleSender(appid, appkey);
    	
    	ArrayList<String> params = new ArrayList<String>();
    	params.add(number);
    	SmsSingleSenderResult singleSenderResult = singleSender.sendWithParam("86", mobile, tmplId, params, "", "", "");
    	return singleSenderResult.result;
	}
	
	public static int sendRenter(String mobile,String time1 ,String time2 ,String hotline) throws Exception {
		int tmplId = 48543;
		SmsSingleSender singleSender = new SmsSingleSender(appid, appkey);
    	
    	ArrayList<String> params = new ArrayList<String>();
    	params.add(time1);
    	params.add(time2);
    	params.add(hotline);
    	SmsSingleSenderResult singleSenderResult = singleSender.sendWithParam("86", mobile, tmplId, params, "", "", "");
    	return singleSenderResult.result;
	}
	
	public static int sendRenter(String mobile,String time1 ,String hotline) throws Exception {
		int tmplId = 48546;
		SmsSingleSender singleSender = new SmsSingleSender(appid, appkey);
    	
    	ArrayList<String> params = new ArrayList<String>();
    	params.add(time1);
    	params.add(hotline);
    	SmsSingleSenderResult singleSenderResult = singleSender.sendWithParam("86", mobile, tmplId, params, "", "", "");
    	return singleSenderResult.result;
	}
	
	
    public static void main(String[] args) {
    	try {
//    		System.out.println(sendSMSInvitation("18362586403", "2358"));
//    		System.out.println(sendRenter("15962257550", DateUtil.renterSMS(System.currentTimeMillis()), DateUtil.renterSMS(System.currentTimeMillis()), "18936096300"));
    		System.out.println(sendRenter("15962257550",  DateUtil.renterSMS(System.currentTimeMillis()), "18936096300"));
    		
    		// 请根据实际 appid 和 appkey 进行开发，以下只作为演示 sdk 使用
//    		int appid = 1400012825;
//    		String appkey = "9df551c89b6836e9aedd0338edb58a1e";
    		
//    		String phoneNumber1 = "12362586404";
//    		String phoneNumber2 = "12345678902";
//    		int tmplId = 19279;

    		// 初始化单发
//	    	SmsSingleSender singleSender = new SmsSingleSender(appid, appkey);
//	    	SmsSingleSenderResult singleSenderResult;
//	
//	    	// 普通单发
//	    	singleSenderResult = singleSender.send(0, "86", phoneNumber2, "测试短信，普通单发，深圳，小明，上学。", "", "");
//	    	System.out.println(singleSenderResult);
	
	    	// 指定模板单发
	    	// 假设短信模板内容为：测试短信，{1}，{2}，{3}，上学。
//	    	ArrayList<String> params = new ArrayList<String>();
//	    	params.add("小明");
//	    	params.add("weixinhao123");
//	    	singleSenderResult = singleSender.sendWithParam("86", phoneNumber1, tmplId, params, "", "", "");
	    	
//	    	System.out.println(singleSenderResult);
	    	
	    	// 初始化群发
//	    	SmsMultiSender multiSender = new SmsMultiSender(appid, appkey);
//	    	SmsMultiSenderResult multiSenderResult;
	
	    	// 普通群发
	    	// 下面是 3 个假设的号码
//	    	ArrayList<String> phoneNumbers = new ArrayList<String>();
//	    	phoneNumbers.add(phoneNumber1);
//	    	phoneNumbers.add(phoneNumber2);
//	    	phoneNumbers.add(phoneNumber3);
//	    	multiSenderResult = multiSender.send(0, "86", phoneNumbers, "测试短信，普通群发，深圳，小明，上学。", "", "");
//	    	System.out.println(multiSenderResult);

	    	// 指定模板群发
	    	// 假设短信模板内容为：测试短信，{1}，{2}，{3}，上学。
//	    	ArrayList<String> params = new ArrayList<String>();
//	    	params = new ArrayList<String>();
//	    	params.add("小明");
//	    	params.add("weixinhao123");
//	    	multiSenderResult = multiSender.sendWithParam("86", phoneNumber1, tmplId, params, "", "", "");
//	    	System.out.println(multiSenderResult);
    	} catch (Exception e) {
			e.printStackTrace();
		}
    }
}
